/* 
 * File:   parsolver.cpp
 * Author: tomas
 *
 * Created on May 3, 2009, 5:34 PM
 */

#include <stdlib.h>

#include "parstack.h"
#include "Instance.h"
#include "instancereader.h"

#include <boost/mpi.hpp>

namespace mpi = boost::mpi;

void runMainProcess(mpi::environment& env, mpi::communicator& world);
void runOtherProcess(mpi::environment& env, mpi::communicator& world);
class InstanceI;
InstanceI * instp;

/*
 * 
 */
int main(int argc, char** argv) {
	mpi::environment env(argc, argv);
	mpi::communicator world;


	InstanceReader rdr = InstanceReader(std::cin);
	//Instance inst = rdr.readInstance();
	instp = &(rdr.readInstance());


	if (world.rank() == 0)
	{
		runMainProcess(env, world);
	}
	else
	{
		runOtherProcess(env, world);
	}
	

	//Solver s(inst);
	//s.solve();

    return (EXIT_SUCCESS);
}

//////////////////////////////////////////////////////////////////////////
void runMainProcess(mpi::environment& env, mpi::communicator& world)
{
	
}

//////////////////////////////////////////////////////////////////////////
void runOtherProcess(mpi::environment& env, mpi::communicator& world)
{

}

//////////////////////////////////////////////////////////////////////////
struct MockInstance: public InstanceI
{

	virtual unsigned getPenalty(const unsigned x, const unsigned y) const
	{
		return 1;
	}

	virtual unsigned getPenalty(const utils::coords_t c) const
	{
		return 1;
	}

	//get collection of coordinates of horses
	virtual const horses_t& getHorses() const 
	{
		return horses;
	}

	//velikost sachovnice
	virtual unsigned n() const
	{
		return 5;
	}

	//pocet jezdcu
	virtual unsigned k() const
	{
		return 5;
	}

	//max. pocet tahu do reseni
	virtual unsigned q() const
	{
		return 5;
	}

	//virtual dtor.
	virtual ~MockInstance() {}

private:

	horses_t horses;
};

//////////////////////////////////////////////////////////////////////////
void testPStack()
{
	ParStack p(&MockInstance());
	StackRecord::boardLayout_t lay;
	StackRecord sr(lay);

	p.push(sr);

	for(int i=1;i<50;++i) {
		StackRecord sr(lay,p.top(),Move(),13);
		p.push(sr);
	}



	std::vector<ParStack::workUnit_t> units = p.divide(2,100);
	for (unsigned i = 0; i<units.size(); ++i)
	{
		std::cout << units[i].size() << "\n";
	}
}

